package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderItemEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @ClassName RabbitTestController
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/7/14
 * @Version 1.0
 */
@RestController
public class RabbitTestController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("sendMsg")
    public String sendMsg(@RequestParam(value = "num",defaultValue = "10") Integer num){
        //发送多次
        for(int i=0;i<num;i++){
            if(i%2==0){
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setAutoConfirmDay(1);
                orderEntity.setBillContent("hello"+i);
                rabbitTemplate.convertAndSend("java-direct","hello.java",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
            }else {
                OrderItemEntity itemEntity = new OrderItemEntity();
                itemEntity.setGiftGrowth(1);
                itemEntity.setOrderSn("hahah"+i);
                rabbitTemplate.convertAndSend("java-direct","hello11.java",itemEntity,new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "ok";
    }
}
